
import React, { useState, useRef } from 'react';
import { postList, postAdd, postUpdate, postDelete } from  '@/services/ant-design-pro/post';

import ListView from '@/components/Base/ListView'
import Helper from '@/components/Base/helper'

const SysDetp: React.FC = () => {
  const columns = [
    Helper.Table('参数编号', 'id').val,
    Helper.Table('参数名称', 'postName').val,
    Helper.Table('参数key', 'postCode').val,
    Helper.Table('参数value', 'order').val,
    Helper.Table('状态', 'status').val,
  ];

  const formColumns = [
    Helper.Form('参数名称', 'paramName')
      .FIP({
        rules: Helper.Rule().Require('不得为空').val,
      }).Width('md').val,
    Helper.Form('参数key', 'label')
    .FIP({
      rules: Helper.Rule().Require('不得为空').val,
    }).Width('md').val,
    Helper.Form('参数value', 'value')
    .FIP({
      rules: Helper.Rule().Require('不得为空').val,
    }).Width('md').val,
    Helper.Form('系统内置', 'status').Radio({0: '正常', 1: '停用'}).Width('md').val,
    Helper.Form('前台显示', 'status').Select({0: '是', 1: '否'}).Width('md').val,

    Helper.Form('备注', 'remark').Textarea().Width('md').val
  ]

  const values = {
    headerTitle: '参数列表',

    ACTIONS: [
      {type: 'NEW', submit: (id, body) => {
        console.log('ud', id, body)
        if (id) {
          return postUpdate(id, body)
        }
        return postAdd(body)
      }, beforeSubmit: (values: any) => ({...values, parentId: values.parentId && values.parentId[0]}) },
      {type: 'EDIT'},
      {type: 'DELETE', submit:(record: {id: number}) => postDelete(record.id)}
    ],
    columns,
    request: postList,
    formColumns,
    initialValues: {
      parentId: [1],
      postName: '天神下凡'
    }
  }

  return (
    <ListView {...values} />
  );
};

export default SysDetp;

